package gui;

import javax.swing.*;
import java.awt.Component;
import javax.swing.table.TableCellRenderer;
import java.awt.Color;
import javax.swing.table.DefaultTableCellRenderer;


/**
 * A class to implement Combo boxes in a JTable
 * @author Sarah Wegner
 */
public class CellRenderer extends DefaultTableCellRenderer implements TableCellRenderer {
    public CellRenderer() {
        super();
    }//CellRenderer

    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column)
    {
        Component cell = super.getTableCellRendererComponent
                         (table, value, isSelected, hasFocus, row, column);
        int colCount = table.getColumnCount();
        String colName = table.getColumnName(colCount-1);

        if (isSelected) {
            setForeground(table.getSelectionForeground());
            super.setBackground(table.getSelectionBackground());
        }
        else if((column < colCount) && (column >=0) && ((Boolean)table.getValueAt(row,colCount-1)) && (colName.equals("Deleted"))){
            setForeground(table.getForeground());
            setBackground(Color.getHSBColor(0, 0, (float)0.863));
        }//else-if
        else{
            setForeground(table.getForeground());
            setBackground(table.getBackground());
        }//else
        // Select the current value
        return cell;
    }//getTableCellRendererComponent

}//MyComboBoxRenderer
